package ru.mipt.board.net
import scala.actors._
import java.sql.{Connection,DriverManager}
import org.squeryl.PrimitiveTypeMode._
import org.squeryl.adapters.PostgreSqlAdapter
import org.squeryl._
/**
 * Created by IntelliJ IDEA.
 * User: IL
 * Date: 19.09.2010
 * Time: 14:40:52
 * To change this template use File | Settings | File Templates.
 */



class MainActor extends Actor{
    val users = new scala.collection.mutable.HashSet[String]
    val messageset = new scala.collection.mutable.HashSet[BoardMessage]
    var userID = 0
    val numposts = 6777777
    val posts = new Array[Boolean](numposts)
    /*Class.forName("org.postgresql.Driver");
    val connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/Board","postgres","qaz")
    connection.setAutoCommit(false)
    import BoardDb._
    println("new")  */
    def act={
        loop{
            receive{
                case (messages:List[BoardMessage],callback) => process(messages)
                case _ =>
            }
        }
    }

    def process(messages: List[BoardMessage])={
        for (boardMessage <- messages) {

                messageset add boardMessage
                if( ! (users contains boardMessage.username ))users add boardMessage.username
            }
    }
}

/*object BoardDb extends Schema {
    val db_users = table[(Long,String)]
    val db_messages = table[BoardMessage]
    override  def drop = super.drop
}  */